<?php
class ControllerModuleCartQuickView extends Controller { 
    protected function index() {      
        $this->data['template'] = $this->config->get('config_template');
        $this->data['checkout'] = HTTPS_SERVER . 'index.php?route=checkout/cart';
        $this->data['loadcart'] = HTTPS_SERVER . 'index.php?route=module/cart_quickview/loadCart'; 
                        
        if($this->cart->hasProducts()){             
            $this->load->model('tool/seo_url');
            $this->load->model('catalog/category');
            $this->load->model('catalog/product');
           
            $products = $this->cart->getProducts(); 
            $products_info = array();
            foreach($products as $product){
                $option_data = array();
                /*
                foreach ($product['option'] as $option) {
                	$option_data[] = array(
                    	'name'  => $option['name'],
                    	'value' => $option['value']
                	);                
            	}
            	*/                
               	$option_data[] = $this->model_catalog_product->getSizeOption($product['option']);
                
                if ($product['image']) {
                    $image = $product['image'];
                } 
                else {
                    $image = 'no_image.jpg';
                }                                     
                $path = '&path=' . $this->model_catalog_product->getCategoriesPath($product['product_id']);                
                
                $products_info[] = array(
                    'key'        => $product['key'],
                    'name'       => $product['name'],
                    'shortname'  => $product['name'],
                    'option'     => $option_data,
                    'quantity'   => $product['quantity'], 
                    'price'      => $this->currency->formatPrice($product['price']), 
                    'href'       => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $path . '&product_id=' . $product['product_id']),           
                );              
            }
            
            $this->data['products'] = $products_info;
            $this->data['subtotal'] = $this->currency->formatPrice($this->cart->getSubTotal());  
        }
        else{ 
            $this->data['products'] = null;   
        }

        $this->id = 'cart_quickview';
            
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/cart_quickview.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/module/cart_quickview.tpl';    
        } 
        else {
            $this->template = 'default/template/module/cart_quickview.tpl';
        }
         
        $this->render();
    }
    
    public function loadCart() {      
        $this->data['template'] = $this->config->get('config_template');
        $this->data['checkout'] = HTTPS_SERVER . 'index.php?route=checkout/cart';
        $this->data['loadcart'] = HTTPS_SERVER . 'index.php?route=module/cart_quickview/loadCart';  
                       
        if($this->cart->hasProducts()){             
            $this->load->model('tool/seo_url');
            $this->load->model('catalog/category'); 
            $this->load->model('catalog/product');
           
            $products = $this->cart->getProducts(); 
            $products_info = array();              
            foreach($products as $product){
                $option_data = array();  
                $option_data[] = $this->model_catalog_product->getSizeOption($product['option']);  
                
                if ($product['image']) {
                    $image = $product['image'];
                } 
                else {
                    $image = 'no_image.jpg';
                }                                                     
                $path = '&path=' . $this->model_catalog_product->getCategoriesPath($product['product_id']);                
                
                $products_info[] = array(
                    'key'        => $product['key'],
                    'name'       => $product['name'],
                    'shortname'  => $product['name'],
                    'option'     => $option_data,
                    'quantity'   => $product['quantity'], 
                    'price'      => $this->currency->formatPrice($product['price']), 
                    'href'       => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $path . '&product_id=' . $product['product_id']),           
                );              
            }
               
            $this->data['products'] = $products_info;
            $this->data['subtotal'] = $this->currency->formatPrice($this->cart->getSubTotal());  
        }
        else{ 
            $this->data['products'] = null;   
        }
            
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/cart_quickview_ajax.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/module/cart_quickview_ajax.tpl';    
        } 
        else {
            $this->template = 'default/template/module/cart_quickview_ajax.tpl';
        }
        
        $this->response->setOutput($this->render(true), $this->config->get('config_compression')); 
    }
}
?>